﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using CommDll;

namespace InstitutionAssitant
{
    /// <summary>
    /// ClassName:frmInfoDetail
    /// Version:1.0
    /// Date:2016-07-01
    /// Author:seanouyang
    /// </summary>
    /// <remarks>
    /// 本类是一WinForm 窗体,本窗体主要为显示DataGridView指定行信息
    /// </remarks>

    public partial class frmInfoDetail : DevComponents.DotNetBar.OfficeForm
    {
        #region 01.自定义属性
        public int m_nRow = -1;
        public DataGridView m_dgv;
        #endregion

        public frmInfoDetail()
        {
            InitializeComponent();
        }

        #region 02.自定义方法
        /// <summary>
        /// 按条件显示相关的数据信息
        /// </summary>
        private void _queryInfo()
        {
            if (!(m_nRow >= 0 && m_nRow < m_dgv.Rows.Count)) { 
                return;
            }
            // 01 superGridControl1初始化(数据及显示样式)
            superGridControl1.PrimaryGrid.Rows.Clear();
            // 背景样式
            DevComponents.DotNetBar.SuperGrid.Style.Background background1 = new DevComponents.DotNetBar.SuperGrid.Style.Background();
            background1.Color1 = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
            background1.Color2 = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
            DevComponents.DotNetBar.SuperGrid.Style.Background background2 = new DevComponents.DotNetBar.SuperGrid.Style.Background();
            background2.Color1 = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
            background2.Color2 = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(192)))), ((int)(((byte)(255)))));
            // 02 按条件自动生成相应的数据信息项
            int i = 0;
            for (int j=0;j < m_dgv.ColumnCount;j++)
            {
                if (m_dgv.Columns[j].Width > 10 && m_dgv.Columns[j].HeaderText.Contains(txtKey.Text.Trim()) && !m_dgv.Columns[j].HeaderText.Equals("□"))
                {
                    i++;
                    DevComponents.DotNetBar.SuperGrid.GridRow gridRow = new DevComponents.DotNetBar.SuperGrid.GridRow();
                    DevComponents.DotNetBar.SuperGrid.GridCell gridCell = new DevComponents.DotNetBar.SuperGrid.GridCell();
                    // Cell1
                    gridCell.Value = string.Format("{0}", i);
                    gridCell.CellStyles.Default.Alignment = DevComponents.DotNetBar.SuperGrid.Style.Alignment.MiddleCenter;
                    gridCell.CellStyles.Default.Background = background1;
                    gridCell.CellStyles.Selected.Background = background2;
                    gridRow.Cells.Add(gridCell);
                    // Cell2
                    gridCell = new DevComponents.DotNetBar.SuperGrid.GridCell();
                    gridCell.Value = string.Format("{0}", m_dgv.Columns[j].HeaderText);
                    gridCell.CellStyles.Default.Alignment = DevComponents.DotNetBar.SuperGrid.Style.Alignment.MiddleCenter;
                    gridCell.CellStyles.Default.Background = background1;
                    gridCell.CellStyles.Selected.Background = background2;
                    gridRow.Cells.Add(gridCell);
                    // Cell3
                    gridCell = new DevComponents.DotNetBar.SuperGrid.GridCell();
                    gridCell.Value = string.Format("{0}", m_dgv.Rows[m_nRow].Cells[j].Value.ToString());
                    gridRow.Cells.Add(gridCell);
                    // Row
                    superGridControl1.PrimaryGrid.Rows.Add(gridRow);
                }
            }
        }
        #endregion

        #region 03.系统事件方法
        private void frmInfoDetail_Load(object sender, EventArgs e)
        {
            lblTitle.Text = this.Text;
            btnQuery_Click(null, null);
        }
        
        private void btnReturn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {
            _queryInfo();   
        }

        private void superGridControl1_KeyDown(object sender, KeyEventArgs e)
        {
            // Ctrl+C 复制
            if (e.Control & e.KeyCode == Keys.C)
            {
                Clipboard.SetDataObject(superGridControl1.ActiveCell.Value.ToString());
                e.Handled = true;
            }
        }

        private void txtKey_KeyDown(object sender, KeyEventArgs e)
        {
            // 回车后直接查询
            if (e.KeyValue == 13)
            {
                _queryInfo();
            }
        }
        #endregion
    }
}